package StudyCode.summary.myfile;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertsLongToByteLength8 {
	public static void main(String[] argv) throws Exception {
		int a = 2;
		System.out.println(a + "转为长度为8的字节数组:");
		byte[] result = longToByteArray(a);
		System.out.println(Arrays.toString(result));
	}

	private static byte[] longToByteArray(int a) {
		byte[] result = new byte[8];

		result[0] = (byte) ((a >> 56) & 0xFF);
		result[1] = (byte) ((a >> 48) & 0xFF);
		result[2] = (byte) ((a >> 40) & 0xFF);
		result[3] = (byte) ((a >> 32) & 0xFF);
		result[4] = (byte) ((a >> 24) & 0xFF);
		result[5] = (byte) ((a >> 16) & 0xFF);
		result[6] = (byte) ((a >> 8) & 0xFF);
		result[7] = (byte) (a & 0xFF);

		return result;
	}
}
